import requests
from bs4 import BeautifulSoup
import pandas as pd


a=10
#url="https://sz.lianjia.com/ershoufang/pg4rs福田/"
#地区
region=[]
#名称
name=[]
#价格
price=[]
urls=[]
#单价
unitprice=[]
#面积
area=[]
for i in range(2,3):
    urls.append("https://sz.lianjia.com/ershoufang/"+"pg"+i.__str__()+"rs福田/")


for url in urls:
    res = requests.get(url)
    soup = BeautifulSoup(res.text, 'html.parser')
    # print(soup.findAll(class_='positionInfo'))

    for li in soup.findAll(class_='positionInfo'):
        #保存花园名称
        name.append(li.a.text)
        # 保存地区
        region.append(li.a.next_sibling.next_sibling.text)

    for li in soup.findAll(class_='totalPrice totalPrice2'):
        #保存价格
        price.append(li.span.text)

    for li in soup.findAll(class_='unitPrice'):
        #保存单价
        unitprice.append(li.span.text)


    for li in soup.findAll(class_='houseInfo'):
        #保存面积
        area.append(li.text[6:li.text.find('平')])






# test=pd.DataFrame(columns=["name"],data=a)
# test.to_csv('E:/test.csv')
